package com.dd.shop4j.common.helper;

import java.util.ArrayList;
import java.util.List;

class Table {

	private String name;
	private String comment;
	private List<Column> columns;
	private IDialect dialect;

	public Table() {
		super();
	}

	public Table(String name, String comment) {
		super();
		this.name = name;
		this.comment = comment;
	}
	
	public Table(String name, String comment, IDialect dialect) {
		this(name, comment);
		this.dialect = dialect;
	}

	public String getImports() {
		return this.dialect.getImports(columns);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
	
	public void setDialect(IDialect dialect) {
		this.dialect = dialect;
	}
	
	public IDialect getDialect() {
		return dialect;
	}
	
	public List<Column> getColumns() {
		return columns;
	}
	
	public void setColumns(List<Column> columns) {
		this.columns = columns;
	}
	
	public void addColumn(Column column) {
		if (columns == null) {
			columns = new ArrayList<Column>();
		}
		columns.add(column);
	}

	class Column {
		private String name;
		private String type;
		private boolean pk;
		private boolean nullable;
		private boolean auto;
		private String defaultValue;
		private int length;
		private String commect;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		public boolean isAuto() {
			return auto;
		}
		
		public void setAuto(boolean auto) {
			this.auto = auto;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public boolean isPk() {
			return pk;
		}

		public void setPk(boolean pk) {
			this.pk = pk;
		}

		public boolean isNullable() {
			return nullable;
		}

		public void setNullable(boolean nullable) {
			this.nullable = nullable;
		}

		public String getDefaultValue() {
			return defaultValue;
		}

		public void setDefaultValue(String defaultValue) {
			this.defaultValue = defaultValue;
		}

		public int getLength() {
			return length;
		}

		public void setLength(int length) {
			this.length = length;
		}

		public String getCommect() {
			return commect;
		}

		public void setCommect(String commect) {
			this.commect = commect;
		}
		
		public String getSQLType(){
			return dialect.getSQLType(type);
		}
		
		public String getJAVAType() {
			return dialect.getJAVAType(type);
		}

	}
}
